<?php


namespace App\Model;


use Illuminate\Database\Eloquent\Model;

class SpecValue extends Model
{
    const CREATED_AT = 'createtime';
    const UPDATED_AT = null;

    //表名
    protected $table = 'spec_value';

    /**
     * 根据规格组名称查询规格id
     * @param $spec_id
     * @param $spec_value
     * @return mixed
     */
    public function getSpecValueIdByName($spec_id, $spec_value)
    {
        return self::where(compact('spec_id', 'spec_value'))->value('id');
    }

    /**
     * 新增规格值
     * @param $spec_id
     * @param $spec_value
     * @return false|int
     */
    public function add($spec_id, $spec_value)
    {
        $this->spec_id = $spec_id;
        $this->spec_value = $spec_value;
        return $this->save();
    }

    /**
     * 关联规格组表
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function spec()
    {
        return $this->belongsTo('App\Model\Spec', 'spec_id', 'id');
    }
}
